import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PurchaseOrderVO, PurchaseOrderForm, PurchaseOrderQuery } from '@/api/lingxing/purchaseOrder/types';

/**
 * 查询领星采购单列表
 * @param query
 * @returns {*}
 */

export const listPurchaseOrder = (query?: PurchaseOrderQuery): AxiosPromise<PurchaseOrderVO[]> => {
  return request({
    url: '/lingxing/purchaseOrder/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询领星采购单详细
 * @param id
 */
export const getPurchaseOrder = (id: string | number): AxiosPromise<PurchaseOrderVO> => {
  return request({
    url: '/lingxing/purchaseOrder/' + id,
    method: 'get'
  });
};

/**
 * 新增领星采购单
 * @param data
 */
export const addPurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/lingxing/purchaseOrder',
    method: 'post',
    data: data
  });
};

/**
 * 修改领星采购单
 * @param data
 */
export const updatePurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/lingxing/purchaseOrder',
    method: 'put',
    data: data
  });
};

/**
 * 删除领星采购单
 * @param id
 */
export const delPurchaseOrder = (id: string | number | Array<string | number>) => {
  return request({
    url: '/lingxing/purchaseOrder/' + id,
    method: 'delete'
  });
};

/**
 * 同步领星仓库列表
 * @returns {*}
 */
export const syncData = (data?: PurchaseOrderQuery) => {
  return request({
    url: '/lingxing/purchaseOrder/syncData',
    method: 'post',
    data: data
  });
};

export const getNewestUpdateTime = () => {
  return request({
    url: '/lingxing/purchaseOrder/getNewestUpdateTime',
    method: 'get'
  });
};
